package com.naiyumie.ncalculator;

import java.math.BigDecimal;

import android.content.Intent;
import android.os.Bundle;
import android.text.Editable;
import android.text.TextWatcher;
import android.widget.EditText;

/**
 * 숫자를 몇 퍼센트 증가.
 */
public class Percent03Activity extends KingWangJjangActivity {
	
	EditText etb1 = null, etb2 = null, etb3 = null;
	BigDecimal myNumber;
	String myNumberStr = null;
	BigDecimal myPercent;
	String myPercentStr = null;
	BigDecimal resultValue3;
	String resultValueStr3 = null;
	String msg = null;
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_percent_03);
		Intent fromIntent = getIntent();
		msg = fromIntent.getStringExtra("MSG");
		etb1 = (EditText) findViewById(R.id.etb1);
		etb2 = (EditText) findViewById(R.id.etb2);
		etb3 = (EditText) findViewById(R.id.etb3);
		etb1.addTextChangedListener(increaseTargetPercentWatcher);
		etb2.addTextChangedListener(increaseTargetPercentWatcher);
		this.setMsg(msg);
		this.callMethod();
		tvTitle.setText(R.string.category02);
	}
	
	private final TextWatcher increaseTargetPercentWatcher = new TextWatcher() {
		
		public void beforeTextChanged(CharSequence s, int start, int count, int after) {
			etb3.setText("0");
		}
		
		public void onTextChanged(CharSequence s, int start, int before, int count) {
		}
		
		public void afterTextChanged(Editable s) {
			myNumberStr = nWidgetTool.stringFromEditText(etb1);
			myNumber = nWidgetTool.stringToBigDecimalFromEditText(etb1);
			myPercentStr = nWidgetTool.stringFromEditText(etb2);
			myPercent = nWidgetTool.stringToBigDecimalFromEditText(etb2);
			if (!myNumberStr.equals(null) && !myNumberStr.equals("") && !myPercentStr.equals(null) && !myPercentStr.equals("")) {
				BigDecimal calculate = myPercent.divide(new BigDecimal(100), 4, BigDecimal.ROUND_HALF_UP).add(new BigDecimal(1)).multiply(myNumber);
				resultValueStr3 = String.valueOf(calculate);
				etb3.setText(resultValueStr3);
			}
		}
	};
}
